package shared

import upickle.default._

import scala.collection.immutable.SeqMap
import scala.collection.mutable

/**
 * Created by yz on 18/8/2021
 */
object Pojo {

  case class GetImageResponse(valid: Boolean, base64: String = "", message: String = "")

  object GetImageResponse {

    implicit val rw = macroRW[GetImageResponse]

  }

  implicit val seqMapReadWrite: ReadWriter[SeqMap[String, String]] = {
    readwriter[ujson.Obj].bimap[SeqMap[String, String]](x => {
      val ts = x.toList.map { case (k, v) =>
        (k, ujson.Str(v))
      }
      ujson.Obj.from(ts)
    }, y => {
      val ts = y.value.map { case (k, v) =>
        (k, v.str)
      }
      SeqMap.from(ts)
    })
  }

  object GetFileData {

    case class Response(map: SeqMap[String, String], array: List[Map[String, String]])

    implicit val responseRw = macroRW[Response]

  }

  object GetBoxplotImage {

    type Response = GetImageResponse

  }

  object GetHTissueBoxplotImage {

    case class Request()

    type Response = GetImageResponse

    implicit val requestRw = macroRW[Request]

  }

  object GetMTissueBoxplotImage {

    case class Request(geneName: String, group: String, phenotypes: List[String], datasets: List[String],
                       models: List[String], log: String)

    type Response = GetImageResponse

    implicit val requestRw = macroRW[Request]

  }

  case class TableServerData(rows: ujson.Value, total: Int)

  object TableServerData {

    implicit val rw = macroRW[TableServerData]

  }

  object CircSearch {

    case class Request(geneName: String, chr: String,start:String,end:String)

    implicit val requestRw = macroRW[Request]

  }

  object CircId2GeneName {

    case class Request(circId: String)

    implicit val requestRw = macroRW[Request]

  }


}
